<?php


namespace Wang\Pkg\Extensions\Form;

use Dcat\Admin\Form\Field;

class upImage extends Field
{

    protected $view = 'wangpkg::admin.form.upImage';

    public $compress_state = 0;     //时候开启压缩
    public $compress_width = 700;   //压缩的图片宽度
    public $compress_quality = 0.6; //图片质量
    public $image_type = 'jpeg';    //图片类型

    protected static $css = [];

    protected static $js = [
    ];

    public function render()
    {
        $this->variables['id'] = uniqid();

        $this->variables['compress_state'] = $this->compress_state;
        $this->variables['compress_width'] = $this->compress_width;
        $this->variables['compress_quality'] = $this->compress_quality;
        $this->variables['image_type'] = $this->image_type;

        return parent::render();
    }

    /*
     IMG_COMPRESS=0
     IMG_COMPRESS_WIDTH=700
     IMG_COMPRESS_QUALITY=0.6
     */
    //时候开启压缩    压缩宽度    压缩质量    图片类型
    public function setInfo($state=0,$width=700,$quality=0.6,$image_type=''){
        $this->compress_state = $state;
        $this->compress_width = $width;
        $this->compress_quality = $quality;
        $this->image_type = $image_type;
    }


    public function setValue($value = '')
    {
        if ($value) {
            $this->value = $value;
        }
        return $this;
    }
}
